package service;

import java.awt.event.ItemEvent;
import java.util.ArrayList;
import java.util.List;

import beans.*;
import entities.*;

public class DepositoSrv {

	private static DepositoSrv instancia = null;
		
		public static DepositoSrv getInstancia() {
			if(instancia == null) {
				instancia = new DepositoSrv();
			}
			return instancia;
		}
		
		/**
		 * 
		 * @param deposito
		 * @return
		 */
		public DepositoEntity bean2Entity(DepositoBean deposito) {
			DepositoEntity depositoEntity = new DepositoEntity();
			depositoEntity.setId(deposito.getId());
			depositoEntity.setTipo(deposito.getTipo());
			
			List<ItemDepositoEntity> itemsDepositosEntity = new ArrayList<ItemDepositoEntity>();
			for (ItemDepositoBean itemDepositoBean: deposito.getInsumos()) {
				ItemDepositoEntity itemDepositoEntity = ItemDepositoSrv.getInstancia().bean2Entity(itemDepositoBean);
				itemsDepositosEntity.add(itemDepositoEntity);
			}
			depositoEntity.setInsumos(itemsDepositosEntity);
			return depositoEntity;
		}

		/**
		 * 
		 * @param deposito
		 * @return
		 */
		public DepositoBean entity2Bean(DepositoEntity deposito) {
			DepositoBean depositoBean = new DepositoBean();
			depositoBean.setId(deposito.getId());
			depositoBean.setTipo(deposito.getTipo());
			
			List<ItemDepositoBean> itemsDepositosBean = new ArrayList<ItemDepositoBean>();
			for (ItemDepositoEntity itemDepositoEntity: deposito.getInsumos()) {
				ItemDepositoBean itemDepositoBean = ItemDepositoSrv.getInstancia().entity2Bean(itemDepositoEntity);
				itemsDepositosBean.add(itemDepositoBean);
			}
			depositoBean.setInsumos(itemsDepositosBean);
			return depositoBean;
		}
}

